package com.ruoyi.td.vo;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.ruoyi.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.swing.*;
import java.io.Serializable;
import java.util.List;


@ApiModel(value = "ThingModelVo")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ThingModelVo  extends BaseEntity {
    private static final long serialVersionUID = -1L;

    private  Long Id;

    @ApiModelProperty(value = "产品key")
    private String productKey;
    @ApiModelProperty(value = "模型内容")
    private Model model;


    @Data
    public static class Model{
        private List<Property> properties;
    }


    @Data
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Property {
        private String identifier;
        private DataType dataType;
        private String name;
        private String accessMode = "rw";

        // 描述
        private String description;

        // 单位
        private String unit;
        // 图标id
        private Long iconId;
        // 图标信息
        private Icon icon;

        private String defaultTxt;
    }
    @Data
    public static class DataType {
        private String type;
        private Object specs;

        public <T> Object parse(T value) {
            if (value == null) {
                return null;
            }

            String val = value.toString();
            type = type.toLowerCase();
            switch (type) {
                case "bool":
                case "enum":
                    return val;
                case "int":
                    return Integer.parseInt(val);
                default:
                    return val;
            }

        }
    }


}
